from random import choice, randint


def Csum(num1, num2):
    return num1 + num2


def Csub(num1, num2):
    return num1 - num2


def Cmul(num1, num2):
    return num1 * num2


def Cdiv(num1, num2):
    if num2 == 0:
        print("除数不能为0")
        return 0
    return num1 / num2


operators = ['+', '-', '*', '/']
flag = True
while flag:
    operator = choice(operators)
    if operator == '/':
        num2 = randint(1, 10)
        # 保证 num1 能被 num2 整除
        num1 = num2 * randint(1, 10)
    else:
        num1 = randint(1, 100)
        num2 = randint(1, 100)

    if operator == '+':
        correct_answer = Csum(num1, num2)
    elif operator == '-':
        correct_answer = Csub(num1, num2)
    elif operator == '*':
        correct_answer = Cmul(num1, num2)
    elif operator == '/':
        correct_answer = Cdiv(num1, num2)

    user_answer = float(input(f"请问 {num1} {operator} {num2} 的结果是多少？"))
    if user_answer == correct_answer:
        print("回答正确！")
    else:
        print(f"回答错误，正确答案是 {correct_answer}。")

    conti = input("是否继续答题？ Y/N\n")
    if conti == "Y" or conti == "y":
        flag = True
    else:
        flag = False

